package thread;

/**
 * @author : gscsd
 * @description: 1.
 * @date : 2025/9/27 14:01
 */
public class ThreadCreateExtends {


    public static void main(String[] args) {
        MyThread myThread = new MyThread();

        Thread thread = new Thread(myThread, "继承Thread线程名称...");
        thread.start();

        Thread anonymousThread = new Thread(() -> {
            System.out.println("匿名内部类线程, 线程启动了>>>>" + Thread.currentThread().getName());
        });

        anonymousThread.setName("匿名内部类线程");
        anonymousThread.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("main线程启动了>>>>" + Thread.currentThread().getName());
    }


}

class MyThread extends Thread {
    public MyThread() {
        setName("default name");
    }

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("继承 Thread线程,  线程启动了>>>>" + Thread.currentThread().getName());
    }
}
